package com.deercrowing.takeaway.controller.user;

import com.deercrowing.takeaway.common.exception.BusinessException;
import com.deercrowing.takeaway.common.model.Result;
import com.deercrowing.takeaway.service.SetmealsService;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@Slf4j
@Validated
@RestController
@RequestMapping("user/setmeals")
public class SetmealsWithUserController {

    @Autowired
    SetmealsService setmealsService;

    /**
     * 获取该分类下的套餐信息
     *
     */
    @GetMapping("/list")
    public ResponseEntity selectAll(@RequestParam Short categoryId){
        log.info("传入分类:{}",categoryId);

        if (Objects.isNull(categoryId)){
            throw new BusinessException("传入分类为空");
        }

        return ResponseEntity.ok(Result.OK(this.setmealsService.selectSetmalWithDish(categoryId)));
    }

    @GetMapping("/dish/{id}")
    public ResponseEntity selectDish(@PathVariable @NotNull(message = "主键不能为空") Integer id){
        return ResponseEntity.ok(Result.OK(this.setmealsService.selectDishBySetmealId(id)));
    }
}
